<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLoginAhlifilm extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('ahlifilmModel','',TRUE);
 }

 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('akunahlifilm', 'Account', 'trim|required|xss_clean');
   $this->form_validation->set_rules('pswd', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('ahlifilmloginForm');
   }
   else
   {
     //Go to private area
//     redirect('homeAhlifilm', 'refresh');
	$this->load->view('definegenrePage');
   }

 }

 function check_database($pswd)
 {
   //Field validation succeeded.  Validate against database
   $akunahlifilm = $this->input->post('akunahlifilm');

   //query the database
   $data = $this->ahlifilmModel->login($akunahlifilm, $pswd);

   if($data)
   {
     //$sess_array = array();
     foreach($data as $row)
     {
     $sess_array = array(
         //'id' => $row->id,
         'akunahlifilm' => $row->akunahlifilm
       );
       $this->session->set_userdata('logged_in', $row->akunahlifilm);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}
?>
